package com.blb.day2;

/**
 * 懒汉式单例模式
 */
public class Singleton4 {

    private static Singleton4 instance = null;

    private Singleton4(){
        System.out.println("创建了一个对象");
    }

    public static Singleton4 getInstance(){
        synchronized (Singleton4.class) {
            if (instance == null) {
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                instance = new Singleton4();
            }
        }
        return instance;
    }
}
